/* 拓扑排序
* 1.做法:
    (1) 合并两个集合
    (2) 查询某个元素的祖宗节点
    (3) 记录方法:
        记录每个集合大小: 绑定到根节点上
        记录每个点到根节点的距离: 绑定到每个元素上

* 本题: 
    矩阵压缩, 每个点作为单独点存储, 从1开始编号, 从左向右, 从上到下
*/

#pragma GCC optimize("O1,O2,O3,Ofast")
#pragma GCC optimize("no-stack-protector,unroll-loops,fast-math,inline")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,sse4,sse4.1,sse4.2,ssse3")

#include <iostream>
#include <cstring>
#include <algorithm> 
// #define ONLINE_GUDGE
using namespace std;
#define merge(x, y) fa[find(x)] = find(y)
const int N = 40010;

int n, m, fa[N];

inline int find(int x)
{
    if(x == fa[x]) return x;
    else return fa[x] = find(fa[x]);
}

inline void Print()
{
    cout << "fa[]:\n";
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++)
            cout << "(" << i << ',' << j << ',' << j << ')' << fa[(i-1)*n+j] << ' ';
        cout << endl;
    }
}

int main()
{

    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);   
	cin.tie(0);
    
    cin >> n >> m; 

    for(int i = 1; i <= n * n; i++) fa[i] = i;
    
    for(int i = 1; i <= m; i++){
        int x, y; char op;
        cin >> x >> y >> op;
        int nid, id; nid = id = (x-1)*n+y;
        switch(op){
            case 'R': nid += 1; break; // 向右走一格
            case 'D': nid += n; break; // 向下走一格
        }
        //printf("%d(%d, %d) -> %d(%d, %d)\n", id, x, y, nid, nid/n, nid%n);    
        if(find(nid) == find(id)){
            cout << i << endl; return 0;
        }
        merge(id, nid);
        //cerr << "----------------i: " << i << "-------------------------" << endl;
        //Print();
    }
    cout << "draw\n";
    Print();
    return 0;
}
